﻿using UnityEngine;
using System.Collections;

public class LoginWindow : BaseWidget 
{
    public UIInput NameInput;
    public UILabel TipsLabel; 
    public override void OnLoad()
    {
      
        NameInput.value = System.Guid.NewGuid().ToString("N").Substring(0,20);
    }

    public override void OnExit()
    {
        
    }

    public void OnClick_Login() 
    {
        TipsLabel.gameObject.SetActive(false);
        if (NameInput.value.Trim() == "") 
        {
            TipsLabel.gameObject.SetActive(true);
            TipsLabel.text = "名称不可为空";
            return;
        }
        Game.Net.NetWork.SetConcnectDelegate(ConnectServerRet);
        Game.Net.NetWork.ConnectToServer("127.0.0.1",54161,0);
    }

    public void ConnectServerRet(bool bSuccess, string result) 
    {
        if (bSuccess == false) 
        {
            TipsLabel.gameObject.SetActive(true);
            TipsLabel.text = "连接服务器失败 "+ result;
            return;
        }

        Game.Packet.SendUserLogin(NameInput.value);
    }

    //服务器返回 角色名重名
    public void ServerRetUserNameSame() 
    {
        TipsLabel.gameObject.SetActive(true);
        TipsLabel.text = "该角色名已存在";
    }
}
